package com.ckk.springcloud.controller;

import com.ckk.springcloud.feigin.HystrixFeign;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author 陈昆昆
 * @version 1.0
 * @date 2020/6/16 16:28
 */
@RestController
public class HystrixController {
    @Autowired
    private HystrixFeign hystrixFeign;

    @GetMapping("payment/hystrix/getok")
    public String getok(){
        return hystrixFeign.getok();
    }

    @GetMapping("payment/hystrix/isNotok")
//    @HystrixCommand(fallbackMethod = "paymentInfo_TimeoutHandler",commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
//    })
    public String getisnotok(Integer id){
//        try {
//            TimeUnit.SECONDS.sleep(4);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        return hystrixFeign.getisnotok();
    }

    // 异常后调用的方法
    public String paymentInfo_TimeoutHandler(Integer id){
        return "服务超时，调用服务降级成功";
    }
}
